﻿package mortal.game.view.skill.panel.render
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class SkillLearnDesc extends GSprite
    {
        private var _bg:ScaleBitmap;
        private var _titleBg1:GBitmap;
        private var _titleBg2:GBitmap;
        private var _title1:GBitmap;
        private var _title2:GBitmap;
        private var _txtName:GTextFiled;
        private var _txtType:GTextFiled;
        private var _txtLevel:GTextFiled;
        private var _line1:ScaleBitmap;
        private var _line2:ScaleBitmap;
        private var _txtLevel2:GTextFiled;
        private var _txtDesc:GTextFiled;
        private var _txtHowToGet:GTextFiled;
        private var _cSelect:GCheckBox;
        private var _txtUpLevel:GTextFiled;
        private var _txtNeed:GTextFiled;
        private var _txtSkillPoint:GTextFiled;
        private var _txtBook:GTextFiled;
        private var _btnLearn:GButton;
        private var _info:SkillInfo;
        private var _line3:ScaleBitmap;
        private var _txtHaveSkillPoint:GTextFiled;

        public function SkillLearnDesc()
        {
            return;
        }// end function

        public function updateHaveSkillPoint(param1:int) : void
        {
            this._txtHaveSkillPoint.htmlText = Language.getStringByParam(21068, param1);
            return;
        }// end function

        public function updateData(param1:SkillInfo) : void
        {
            var _loc_2:ItemInfo = null;
            if (param1 == null)
            {
                return;
            }
            this._info = param1;
            this._txtName.htmlText = Language.getStringByParam(21069, param1.skillName);
            this._txtType.text = SkillUtil.getSkillUseTypeName(param1.tSkill);
            this._txtLevel2.text = Language.getStringByParam(21070, param1.tSkill.skillLevel.toString());
            this._txtDesc.htmlText = SkillUtil.getSkillDesc(param1.tSkill.skillId);
            this._btnLearn.label = Language.getString(20095);
            if (!param1.learned)
            {
                this._txtHowToGet.textColor = 65280;
                this._txtHowToGet.text = "";
                if (param1.tSkill.needSkillBook > 0)
                {
                    _loc_2 = ItemConfig.instance.getConfig(param1.tSkill.needSkillBook);
                    if (_loc_2 != null && _loc_2.decomposeItems != null && _loc_2.decomposeItems != "")
                    {
                        this._txtHowToGet.htmlText = _loc_2.decomposeItems;
                    }
                    else
                    {
                        this._txtHowToGet.text = Language.getString(21065);
                    }
                }
                else if (param1.isEquipSkill)
                {
                    this._txtHowToGet.text = "";
                }
                else
                {
                    this._txtHowToGet.text = Language.getString(21071);
                }
                if (!param1.learnable())
                {
                    this._txtLevel.filters = [FilterConst.colorFilter];
                    this._txtLevel.htmlText = Language.getStringByParam(20110, Language.getString(20113), 0, param1.maxLevel);
                    DisplayUtil.setEnabled(this._btnLearn, false);
                }
                else
                {
                    this._txtLevel.filters = [];
                    this._txtLevel.htmlText = Language.getStringByParam(20110, Language.getString(20112), 0, param1.maxLevel);
                    DisplayUtil.setEnabled(this._btnLearn, true);
                    this._btnLearn.label = Language.getString(20094);
                }
                this.updateNextLevelInfo(param1, param1.tSkill);
            }
            else
            {
                this._txtHowToGet.textColor = 15851074;
                this._txtHowToGet.text = Language.getString(20117);
                if (param1.isMaxLevel())
                {
                    this._txtLevel.filters = [FilterConst.colorFilter];
                    this._txtLevel.htmlText = Language.getStringByParam(20110, Language.getString(20107), param1.skillLevel, param1.maxLevel);
                    DisplayUtil.setEnabled(this._btnLearn, false);
                    this._txtUpLevel.htmlText = Language.getStringByParam(20086, "#ffff00", Language.getString(20107));
                    this._txtNeed.htmlText = Language.getStringByParam(20088, "#ffff00", 0);
                    this._txtSkillPoint.htmlText = Language.getStringByParam(20090, "#ffff00", 0);
                }
                else if (param1.upgradable())
                {
                    this._txtLevel.filters = [];
                    this._txtLevel.htmlText = Language.getStringByParam(20110, Language.getString(20111), param1.skillLevel, param1.maxLevel);
                    DisplayUtil.setEnabled(this._btnLearn, true);
                    this.updateNextLevelInfo(param1, param1.nextSkill);
                }
                else
                {
                    this._txtLevel.filters = [FilterConst.colorFilter];
                    this._txtLevel.htmlText = Language.getStringByParam(20110, Language.getString(20111), param1.skillLevel, param1.maxLevel);
                    DisplayUtil.setEnabled(this._btnLearn, false);
                    this.updateNextLevelInfo(param1, param1.nextSkill);
                }
            }
            if (param1.tSkill.targetSelect == ESkillTargetSelect._ESkillTargetSelectMouse || param1.tSkill.targetSelect == ESkillTargetSelect._ESkillTargetSelectMouseFront)
            {
                this._cSelect.label = Language.getString(20092);
                this.addChild(this._cSelect);
                this._cSelect.selected = param1.autoUse;
            }
            else if (param1.tSkill.targetSelect == ESkillTargetSelect._ESkillTargetSelectMouseDirection && param1.tSkill.type != ESkillType._ESkillTypeTransfer)
            {
                this._cSelect.label = Language.getString(20093);
                this.addChild(this._cSelect);
                this._cSelect.selected = param1.autoUse;
            }
            else
            {
                DisplayUtil.removeMe(this._cSelect);
            }
            return;
        }// end function

        private function updateNextLevelInfo(param1:SkillInfo, param2:TSkill = null) : void
        {
            var _loc_3:ItemData = null;
            var _loc_4:String = null;
            if (param1.isLevelEnough(param2))
            {
                this._txtUpLevel.htmlText = Language.getStringByParam(20086, "#F8e9cc", param2.levelLimit);
            }
            else
            {
                this._txtUpLevel.htmlText = Language.getStringByParam(20086, "#ff0000", param2.levelLimit);
            }
            if (param1.isCoinEnough(param2))
            {
                this._txtNeed.htmlText = Language.getStringByParam(20088, "#F8e9cc", param2.needCoin);
            }
            else
            {
                this._txtNeed.htmlText = Language.getStringByParam(20088, "#ff0000", param2.needCoin);
            }
            if (param1.isSkillPointEnough(param2))
            {
                this._txtSkillPoint.htmlText = Language.getStringByParam(20090, "#F8e9cc", param2.needSkillPoint);
            }
            else
            {
                this._txtSkillPoint.htmlText = Language.getStringByParam(20090, "#ff0000", param2.needSkillPoint);
            }
            if (param1.learned || param1.tSkill.needSkillBook == 0)
            {
                DisplayUtil.removeMe(this._txtBook);
                if (this._btnLearn.parent == null)
                {
                    this.addChild(this._btnLearn);
                }
            }
            else
            {
                if (this._txtBook.parent == null)
                {
                    this.addChild(this._txtBook);
                }
                _loc_3 = new ItemData(param1.tSkill.needSkillBook);
                _loc_4 = "#ff0000";
                if (Cache.instance.pack.backPackCache.getItemByCode(param1.tSkill.needSkillBook, true) != null)
                {
                    _loc_4 = "#9FE9AE";
                }
                this._txtBook.htmlText = Language.getStringByParam(21072, _loc_4, _loc_3.name);
                if (_loc_3.name.length >= 8)
                {
                    this._txtBook.x = 34;
                }
                else
                {
                    this._txtBook.x = 46;
                }
                this._txtBook.mouseEnabled = true;
                this._txtBook.toolTipData = _loc_3;
                DisplayUtil.removeMe(this._btnLearn);
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(-1, 0, 199, 474, this);
            this._titleBg1 = UIFactory.bitmap(ImagesConst.SkillTitle_nameBg, 2, 2, this);
            this._titleBg2 = UIFactory.bitmap(ImagesConst.SkillTitle_nameBg, 2, 305, this);
            this._title1 = UIFactory.gBitmap("", this._titleBg1.x + 7, this._titleBg1.y + 8, this);
            this._title2 = UIFactory.gBitmap("", this._titleBg2.x + 7, this._titleBg2.y + 8, this);
            this._txtName = UIFactory.gTextField("", 8, 33, 200, 20, this);
            this._txtName.textColor = 16763265;
            this._txtType = UIFactory.gTextField("", 130, 33, 200, 20, this);
            var _loc_1:* = GlobalStyle.textFormatPutong;
            this._txtLevel = UIFactory.gTextField("", 8, 52, 200, 20, this);
            this._txtLevel.textColor = 65280;
            this._cSelect = UIFactory.checkBox(Language.getString(20092), 100, 49, 120, 25, this);
            this._cSelect.configEventListener(Event.CHANGE, this.autoSelectChangeHandler);
            this._line1 = UIFactory.bg(0, 76, 200, 2, this, ImagesConst.SplitLine);
            this._line2 = UIFactory.bg(0, 252, 200, 2, this, ImagesConst.SplitLine);
            this._txtLevel2 = UIFactory.gTextField("", 8, 82, 200, 20, this);
            this._txtLevel2.textColor = 15590812;
            _loc_1 = GlobalStyle.textFormatBai;
            _loc_1.leading = 4;
            _loc_1.letterSpacing = 2;
            _loc_1.leading = 4;
            this._txtDesc = UIFactory.gTextField("", 37, 82, 152, 170, this, _loc_1);
            this._txtDesc.multiline = true;
            this._txtDesc.wordWrap = true;
            _loc_1 = GlobalStyle.textFormatPutong;
            _loc_1.leading = 3;
            _loc_1.color = 15590812;
            _loc_1.align = TextFormatAlign.CENTER;
            this._txtHowToGet = UIFactory.gTextField("", 0, 260, 200, 170, this, _loc_1);
            this._txtHowToGet.multiline = true;
            this._txtHowToGet.wordWrap = true;
            _loc_1 = GlobalStyle.textFormatBai;
            _loc_1.letterSpacing = 3;
            this._txtUpLevel = UIFactory.gTextField("", 46, 344, 200, 20, this, _loc_1.clone());
            this._txtNeed = UIFactory.gTextField("", 46, 364, 200, 20, this, _loc_1.clone());
            this._txtSkillPoint = UIFactory.gTextField("", 46, 384, 200, 20, this, _loc_1.clone());
            this._txtBook = UIFactory.gTextField("", 46, 404, 200, 20, this, _loc_1.clone());
            this._btnLearn = UIFactory.gButton("", 72, 412, 62, 22, this);
            this._line3 = UIFactory.bg(0, 440, 200, 2, this, ImagesConst.SplitLine);
            this._txtHaveSkillPoint = UIFactory.gTextField("0", 6, 448, 220, 20, this);
            this._txtHaveSkillPoint.textColor = 65280;
            this._btnLearn.configEventListener(MouseEvent.CLICK, this.learnSkillHandler);
            LoaderHelp.addResCallBack(ResFileConst.skillPanel, this.skillPanelGot);
            return;
        }// end function

        private function skillPanelGot() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._title1.bitmapData = GlobalClass.getBitmapData(ImagesConst.SkillPanel_jnjs);
            this._title2.bitmapData = GlobalClass.getBitmapData(ImagesConst.SkillPanel_sjjn);
            return;
        }// end function

        private function autoSelectChangeHandler(event:Event) : void
        {
            ClientSetting.local.setIsDone(!this._cSelect.selected, IsDoneType.SkillAutoSelectStart + this._info.position - 1);
            ClientSetting.save(true);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._btnLearn.dispose(param1);
            this._btnLearn = null;
            this._cSelect.dispose(param1);
            this._cSelect = null;
            this._txtHowToGet.dispose(param1);
            this._txtHowToGet = null;
            this._line1.dispose(param1);
            this._line1 = null;
            this._line2.dispose(param1);
            this._line2 = null;
            this._title1.dispose(param1);
            this._title1 = null;
            this._title2.dispose(param1);
            this._title2 = null;
            this._titleBg1.dispose(param1);
            this._titleBg1 = null;
            this._titleBg2.dispose(param1);
            this._titleBg2 = null;
            this._txtDesc.dispose(param1);
            this._txtDesc = null;
            this._txtLevel.dispose(param1);
            this._txtLevel = null;
            this._txtLevel2.dispose(param1);
            this._txtLevel2 = null;
            this._txtName.dispose(param1);
            this._txtName = null;
            this._txtNeed.dispose(param1);
            this._txtNeed = null;
            this._txtSkillPoint.dispose(param1);
            this._txtSkillPoint = null;
            this._txtType.dispose(param1);
            this._txtType = null;
            this._txtUpLevel.dispose(param1);
            this._txtUpLevel = null;
            this._txtBook.dispose(param1);
            this._txtBook = null;
            this._txtHaveSkillPoint.dispose();
            this._txtHaveSkillPoint = null;
            this._line3.dispose();
            this._line3 = null;
            return;
        }// end function

        private function learnSkillHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.SkillUpgradeReq, this._info.skillId));
            return;
        }// end function

    }
}
